<?php 
defined('BASEPATH') OR exit('No direct script access allowed');
class Floor extends MY_Controller 
{
	public function __construct()
	{
		parent::__construct();
		$this ->load->helper('url');
		$this ->load->database();
	}
	/**
	 * 楼盘列表显示
	 */
	public function index()
	{

		//分页
		$this->load->library('pagination');
		$perPage =5;
		$config['base_url'] = "http://127.0.0.1/study/htdocs/php5/ci/index.php/floor/index";
		$config['total_rows'] = $this->db->count_all_results('floor');
		$config['per_page'] =$perPage;
		$config['first_link'] = '第一页';
		$config['prev_link'] = '上一页';
		$config['next_link'] = '下一页';
		$config['last_link'] = '最后一页';
		$this->pagination->initialize($config);
		$arr['links'] = $this->pagination->create_links();
		$offset = $this->uri->segment(3);
		 $this->db->limit($perPage,$offset);
		//查看须在后
	    $this->load->model('Floor_model');
		$arr['floor'] = $this->Floor_model->chak();
/*		$this->load->view('home/commont/head');
		$this->load->view('home/commont/left');*/
		$this->load->view('admin/floor/index',$arr);
	}

	/**
	 * 楼盘添加
	 */
	public function add()
	{
		//房屋类型分类
		$this->load->model('Type_model');
		$arr['type'] = $this->Type_model->chak();
		//添加操作
		$method = !empty($_GET) ? 'GET' : 'POST';
		//上面只是用来判断用什么方式提交的，顺便还可以映射一下,使用的话就更方便了
		if(!empty($_POST)){
			$data = array(
				'floor_sn'=>$this->input->post('floor_sn'),
				'sub_area'=>$this->input->post('sub_area'),
				'house_type'=>$this->input->post('house_type'),
				'building_cycle'=>$this->input->post('building_cycle'),
				'sales_address'=>$this->input->post('sales_address'),
				'phone'=>$this->input->post('phone'),
				'floor_address'=>$this->input->post('floor_address'),
				'deve'=>$this->input->post('deve'),
				'payment'=>$this->input->post('payment'),
				);
			 $this->load->model('Floor_model');
			$arr = $this->Floor_model->add($data);
			if(!$arr)
			{
				echo "添加失败";die();
			}
			redirect('admin/floor/index');

		}
/*		$this->load->view('home/commont/head');
		$this->load->view('home/commont/left');*/
		$this->load->view('admin/floor/add',$arr);
	}
	/**
	 * 楼盘信息修改
	 */
	public function update()
	{
		//分类查询
		$this->load->model('Type_model');
		$arr['type'] = $this->Type_model->chak();
		//根据修改传过来的id查询
		$id=$this->input->get('id');
		$this->load->model('Floor_model');
		$arr['floor'] = $this->Floor_model->updas($id);
		// print_r($arr);
		//接受修改传过来的值
		$method = !empty($_GET) ? 'GET' : 'POST';
		//上面只是用来判断用什么方式提交的，顺便还可以映射一下,使用的话就更方便了
		if(!empty($_POST)){
				$id = $this->input->post('floor_id');
				$data = array(
						'floor_sn'=>$this->input->post('floor_sn'),
						'sub_area'=>$this->input->post('sub_area'),
						'house_type'=>$this->input->post('house_type'),
						'building_cycle'=>$this->input->post('building_cycle'),
						'sales_address'=>$this->input->post('sales_address'),
						'phone'=>$this->input->post('phone'),
						'floor_address'=>$this->input->post('floor_address'),
						'deve'=>$this->input->post('deve'),
						'payment'=>$this->input->post('payment'),
					);
			$this->load->model('Floor_model');
			$arr = $this->Floor_model->update($id,$data);
			if(!$arr)
			{
				echo "修改失败";die();
			}
			redirect('admin/floor/index');

		}
/*		$this->load->view('home/commont/head');
		$this->load->view('home/commont/left');*/
		$this->load->view('admin/floor/update',$arr);
	}
	/**
	 * 删除
	 */
	public function del()
	{
		$id=$this->input->get('id');
		$this->load->model('Floor_model');
		$arr = $this->Floor_model->del($id);
		if(!$arr)
			{
				echo "删除失败";die();
			}
			redirect('admin/floor/index');
	}
}	